﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using System.Web.Routing;

using $prjsn$.Common;

using ProjectBase.Core;
using ProjectBase.Mvc;

namespace $safeprojectname$
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes, string suffix = null)
        {
            suffix = suffix ?? string.Empty;

            routes.RouteExistingFiles = false;
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("Index.htm");
            routes.IgnoreRoute("i/{*pathInfo}");
            routes.IgnoreRoute("Scripts/{*pathInfo}");
            routes.IgnoreRoute("Bundles/{*pathInfo}");
            routes.IgnoreRoute("Content/{*pathInfo}");
            routes.IgnoreRoute("files/{*pathInfo}");

            routes.MapRoute("LS1", "{lang}/Articles" + suffix + "/Code/{code}", CreateStoryDefaults(), CreateLangConstraint());
            routes.MapRoute("LS2", "{lang}/Articles" + suffix + "/{category}/{group}", CreateStoryDefaults(), CreateLangConstraint());
            routes.MapRoute("LS3", "{lang}/Articles" + suffix + "/{category}/{group}/{code}", CreateStoryDefaults(), CreateLangConstraint());

            routes.MapRoute("ST1", "Articles" + suffix + "/Code/{code}", CreateStoryDefaults());
            routes.MapRoute("ST2", "Articles" + suffix + "/{category}/{group}", CreateStoryDefaults());
            routes.MapRoute("ST3", "Articles" + suffix + "/{category}/{group}/{code}", CreateStoryDefaults());

            // Home
            routes.MapRoute("LaHo", "{lang}/Home" + suffix + "/{action}/{id}", CreateStandardDefaults(), CreateLangConstraint());
            routes.MapRoute("DfHo", "Home" + suffix + "/{action}/{id}", CreateStandardDefaults());

            // List
            routes.MapRoute("LisL", "{lang}/{controller}" + suffix + "/List/{page}", CreateListDefaults(), CreateLangConstraint());
            routes.MapRoute("List", "{controller}" + suffix + "/List/{page}", CreateListDefaults());

            // standard
            routes.MapRoute("Lang", "{lang}/{controller}" + suffix + "/{action}/{id}", CreateStandardDefaults(), CreateLangConstraint());

            routes.MapRoute("Dflt", "{controller}" + suffix + "/{action}/{id}", CreateStandardDefaults());
            routes.MapRoute("RooL", "{lang}", CreateStandardDefaults(), CreateLangConstraint());
            routes.MapRoute("Root", string.Empty, CreateStandardDefaults());
        }

        static object CreateListDefaults()
        {
            return new
            {
                controller = Str.Controllers.Home,
                action = Str.Actions.List,
                page = string.Empty,
                lang = "en-GB",
            };
        }

        static object CreateStandardDefaults()
        {
            return new
            {
                controller = Str.Controllers.Home,
                action = Str.Actions.Default,
                id = string.Empty,
                lang = "en-GB",
            };
        }

        static object CreateStoryDefaults()
        {
            return new
            {
                controller = Str.Controllers.Story,
                action = Str.Business.Services.Article,
                category = string.Empty,
                group = string.Empty,
                code = string.Empty,
            };
        }

        static object CreateLangConstraint()
        {
            return new { lang = new LangRouteConstraint() };
        }

    }
}